//============================================part database============


import axios from "./axios";
import qs from 'qs'

export function getPartList() {
    return axios.post('/spare_parts/manage/get_list.do').then(res => {
        return Promise.resolve(res.data)
    }, (err) => {
        return Promise.reject(err)
    })
}

export function getPartDetail(sparePartsId) {
    return axios.post('/spare_parts/manage/get_spare_parts_detail.do', qs.stringify({sparePartsId})).then(res => {
        return Promise.resolve(res.data)
    }, err => {
        return Promise.reject(err)
    })

}

export function modifyPart(part) {
    return axios.post('/spare_parts/manage/update_spare_parts.do', qs.stringify(part)).then(res => {
        return Promise.resolve(res.data)
    }, err => {
        return Promise.reject(err)
    })

}

export function modQty({partId, quantity}) {
    return axios.post('/spare_parts/manage/update_parts_stock.do', qs.stringify({
        partId,
        quantity
    })).then(res => Promise.resolve(res.data))
}


export function addPart(part) {
    return axios.post('/spare_parts/manage/add_spare_parts.do', qs.stringify(part)).then(res => {
        return Promise.resolve(res.data)
    }, err => {
        return Promise.reject(err)
    })
}

export function changePartPrice({purchasePrice, salesPrice, partsId}) {
    return axios.post('/spare_parts_price/manage/add_spare_parts_price.do', qs.stringify({
        purchasePrice,
        salesPrice,
        partsId
    })).then(res => Promise.resolve(res.data))
}

export function getPartStockDetail(partsId, belongModule) {
    return axios.post('/spare_parts/manage/update_parts_stock_detail.do', qs.stringify({
        partsId,
        belongModule
    })).then(res => Promise.resolve(res.data))
}
//  显示价格的变动记录
export function showHistoryPrice({partsId}) {
    return axios.post('/spare_parts_price/manage/show_history_price.do', qs.stringify({partsId})).then(res => Promise.resolve(res.data))
}